﻿using SaleManagement.Controllers;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SaleManagement.modules
{
    public partial class frmAdd_Edit_LoaiHang : Form
    {
        private usLoaiHang usLoaiHang;
        private CategoriesController category;
        public frmAdd_Edit_LoaiHang(usLoaiHang usLoaiHang)
        {
            InitializeComponent();
            this.usLoaiHang = usLoaiHang;
            category = new CategoriesController();
            if (usLoaiHang.add == false)
            {
                txtName.Text = usLoaiHang.DataGridView.Rows[usLoaiHang.row].Cells[1].Value.ToString();
                rtbDescription.Text = usLoaiHang.DataGridView.Rows[usLoaiHang.row].Cells[3].Value.ToString();
            }
            else
            {
                this.clear();
            }
        }
        private void clear()
        {
            txtName.Text = "";
            rtbDescription.Text = "";
        }

        private void btnLuu_Click(object sender, EventArgs e)
        {
            CategoriesController warehouse = new CategoriesController();
            string name = txtName.Text;
            string description = rtbDescription.Text;
            if (usLoaiHang.add == true)
            {
                if (warehouse.insertcategory(2, name, description) == true)
                {
                    label1.Text = warehouse.mess;
                    usLoaiHang.onLoad();
                    this.clear();
                }
            }
            else
            {

                if (warehouse.Editcategory(usLoaiHang.Idcategory, name, description) == true)
                {
                    label1.Text = warehouse.mess;
                    usLoaiHang.onLoad();
                    usLoaiHang.Idcategory = null;
                    this.Close();
                }

                labelControl1.Text = warehouse.mess;
            }
        }
    }
}
